package com.moore.service.impl;

import com.moore.bean.Work;
import com.moore.mapper.WorkMapper;
import com.moore.service.WorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WorkServiceImpl implements WorkService {
    @Autowired
    WorkMapper workMapper;

    @Override
    public List<Work> getWorksByPositionId(Integer positionId, String location, String keyword, Integer page, Integer pageSize) {
        int curr = (page - 1) * pageSize;
        return workMapper.getWorks(positionId,location,keyword,curr,pageSize);
    }

    @Override
    public List<Work> getWorksByFilter(Map<String, Object> filters) {
        Integer page = (Integer) filters.remove("page");
        Integer pageSize = (Integer) filters.remove("pageSize");
        int curr = (page - 1) * pageSize;
        return workMapper.getWorksByFilter(filters, curr, pageSize);
    }

    @Override
    public int getWorkCountByPositionId(Integer positionId, String location, String keyword) {
        return workMapper.getWorksCount(positionId,location,keyword);
    }

    @Override
    public int getWorkCountByFilter(Map<String, Object> filters) {
        return workMapper.getWorksByFilterCount(filters);
    }

    @Override
    public Work getWorkById(Integer id) {
        return workMapper.getWorkById(id);
    }
}
